/*
 * ShopInfoPresenter.java
 * business
 *
 * Created by ChenTao on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.shopdetail.info;

import android.os.Bundle;

import com.yidiandao.business.constant.Intents;
import com.yidiandao.business.data.bean.Shop;
import com.yidiandao.business.data.model.IShopModel;
import com.yidiandao.business.data.response.QueryShopInfoResponse;

import java.util.List;

/** 店铺详情-店铺信息-Presenter */
public class ShopInfoPresenter implements ShopInfoContract.Presenter {

    private ShopInfoContract.View mShopInfoView;

    private IShopModel mShopModel;

    private String mSupplierId;

    public ShopInfoPresenter(ShopInfoContract.View view, IShopModel shopModel) {
        mShopInfoView = view;
        mShopModel = shopModel;

        mShopInfoView.setPresenter(this);
    }

    @Override
    public void extraBundle(Bundle bundle) {
        mSupplierId = bundle.getString(Intents.EXTRA_SUPPLIER_ID);
    }

    @Override
    public void start() {

        mShopModel.loadShopInfo(
                mSupplierId,
                mShopInfoView.getPagerTag(),
                new IShopModel.OnLoadShopInfoListener() {
                    @Override
                    public void onSuccess(QueryShopInfoResponse.Data data) {

                        // 其他信息
                        Shop shop = data.getShop();
                        String address = shop.getShopAddress();
                        String servicePhone = shop.getServicePhone();
                        String qq = shop.getQq();

                        QueryShopInfoResponse.StreetInfo streetInfo = data.getStreetInfo();

                        // 店家信息
                        String information = streetInfo.getInformation();
                        // 商家图片
                        List<String> pictures = streetInfo.getPictures();

                        String url = streetInfo.getUrl();
                        String email = streetInfo.getEmail();
                        QueryShopInfoResponse.StreetInfo.AdverInfoBean adverInfo =
                                streetInfo.getAdverInfo();
                        String activeImg = null;
                        String adtiveUrl = null;
                        if (null != adverInfo) {
                            activeImg = adverInfo.getImage();
                            adtiveUrl = adverInfo.getUrl();
                        }

                        mShopInfoView.refreshShopInfo(
                                activeImg,
                                adtiveUrl,
                                information,
                                address,
                                servicePhone,
                                qq,
                                url,
                                email);

                        if (pictures == null || pictures.size() == 0) {
                            mShopInfoView.showShopImagesLayout(false);
                        } else {
                            mShopInfoView.showShopImagesLayout(true);
                            mShopInfoView.refreshShopImages(pictures);
                        }
                    }
                });
    }
}
